﻿/// <reference path="turbo_common.js" />


var $FileUploadContext = TA.Turbo.Common.FileUploadContext = function FileUploadContext()
{
}
$FileUploadContext.prototype._remaining = new Array();
$FileUploadContext.prototype._callBack = null;

$FileUploadContext.prototype.Start = function Start(fileUploadObjects, callBack)
{
	this._remaining = fileUploadObjects;
	this._callBack = callBack;

	this._ProcessNext();
}
$FileUploadContext.prototype._ProcessNext = function _ProcessNext()
{
	if (this._remaining.length == 0)
	{
		this._callBack();
	}
	else
	{
		this._remaining[0]._Submit(this._FileUpload_Complete.bind(this));
	}
}
$FileUploadContext.prototype._FileUpload_Complete = function _FileUpload_Complete(fileUploadObj)
{
	for (var i = 0; i < this._remaining.length; ++i)
	{
		if (this._remaining[i] == fileUploadObj)
		{
			this._remaining.splice(i, 1);
			break;
		}
	}
	this._ProcessNext();
}
